package cn.edu.hit.education.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import cn.edu.hit.education.dialog.CollegeDialog;
import cn.edu.hit.education.pojo.College;
import cn.edu.hit.education.pojo.University;
import cn.edu.hit.education.service.ICollegeService;
import cn.edu.hit.education.view.DepartmentExploreView;
import educationschedule.Activator;
import educationschedule.Application;

public class AddCollegeAction extends Action {
	ICollegeService collegeService = (ICollegeService)Application.applicationContext.getBean("collegeServiceImpl");
	private int universityId;
	private DepartmentExploreView viewPart;
	/**
	 * @wbp.parser.entryPoint
	 */
	public AddCollegeAction(DepartmentExploreView viewPart,int universityId){
		this.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/toolbar/course_code_16px.png"));
		this.setToolTipText("增加学院");
		this.setText("增加学院");
		this.viewPart = viewPart;
		this.universityId = universityId;
	}
	
	@Override
	public void run() {
		Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		CollegeDialog collegeDialog = new CollegeDialog(parentShell);
		College college = new College();
		collegeDialog.setCollege(college);
		if(IDialogConstants.OK_ID == collegeDialog.open()){
			college.setUniversityId(universityId);
			int count = collegeService.insert(college);
			if(count > 0){
				viewPart.refreshNewData(college);
			}
		}
		super.run();
	}

	

}
